<!--
 * @Author: Bob
 * @Date: 2021-03-10 22:56:01
 * @LastEditors: Bob
 * @LastEditTime: 2021-03-10 23:04:03
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <p>
            请问一个yes/no的问题：
            <input v-model="question">
        </p>
        <p>{{ answer }}</p>
    </div>
</body>
<script type="module">
    // https://www.yesno.wtf/api
    import {createApp, ref, watch} from './node_modules/vue/dist/vue.esm-browser.js';
    
    createApp({
        setup(props) {
            const question = ref('')
            const answer = ref('')

            watch(question, async (newValue, oldValue) => {
                const response = await fetch('https://www.yesno.wtf/api')
                const data = await response.json()
                answer.value = data.answer
            })
            return {
                question,
                answer
            }
        }
    }).mount('#app')
</script>
</html>